﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Xml.Serialization;

namespace Barbar.UrlGuard.Dal {
  public class DataContext {
    private int m_LanguageID = 2057;
    private bool m_UseBubbleAlert = true;
    private int m_SecondsToTimeout = 30;
    private EmailAlertSettings m_EmailAlert;
    private Collection<MonitoringChain> m_Chains = new Collection<MonitoringChain>();

    public Collection<MonitoringChain> Chains {
      get { return m_Chains; }
    }

    public int LanguageID {
      get { return m_LanguageID; }
      set { m_LanguageID = value; }
    }

    public bool UseBubbleAlert {
      get { return m_UseBubbleAlert; }
      set { m_UseBubbleAlert = value; }
    }

    public int SecondsToTimeout {
      get { return m_SecondsToTimeout; }
      set { m_SecondsToTimeout = value; }
    }

    public EmailAlertSettings EmailAlert {
      get { return m_EmailAlert; }
      set { m_EmailAlert = value; }
    }

    [XmlIgnore()]
    public IEnumerable<MonitoringEntry> Entries {
      get {
        foreach (MonitoringChain chain in m_Chains) {
          foreach (MonitoringEntry entry in chain.Entries)
            yield return entry;
        }
      }
    }

    public MonitoringEntry GetEntryByID(Guid entryUid) {
      foreach (MonitoringEntry entry in Entries) {
        if (entry.Uid == entryUid)
          return entry;
      }
      return null;
    }
  }
}
